from django.db import models
from datetime import datetime
from django.utils import timezone
# Create your models here.


# 流程表


class ProcessModel(models.Model):
    proname = models.CharField(max_length=30,verbose_name='流程名称')
    prodate = models.DateTimeField(default=datetime.now(),verbose_name='当前创建时间')

    class Meta:
        db_table = 'db_Promodel'
        verbose_name_plural = '流程引擎表'

    def __str__(self):

        return self.proname


# 节点表


class NodeModel(models.Model):
    nodename = models.CharField('节点名称',max_length=30)
    pro_id = models.ForeignKey(ProcessModel,on_delete=models.CASCADE,verbose_name='流程id')

    class Meta:
        db_table = 'db_Node'
        verbose_name_plural = '流程节点表'

    def __str__(self):
        return self.nodename
#  属性表


class AttributeModel(models.Model):
    attrname = models.CharField('节点属性表',max_length=30)
    node_id = models.ForeignKey(NodeModel,on_delete=models.CASCADE,verbose_name='节点')

    class Meta:
        db_table = 'db_attribute'
        verbose_name_plural = '节点属性表'

    def __str__(self):
        return self.attrname


# 员工表


class YuanGongModel(models.Model):
    yname = models.CharField('员工名称',max_length=10,unique=True,null=False)

    class Meta:
        db_table = 'db_Yuangong'
        verbose_name_plural = '员工表'

    def __str__(self):
        return self.yname
# 流程实例表


class WorkflowInstanceModel(models.Model):
    yuan_id = models.ForeignKey(YuanGongModel,on_delete=models.CASCADE,verbose_name='员工id')
    pro_id = models.ForeignKey(ProcessModel,on_delete=models.CASCADE,verbose_name='流程id')




    class Meta:
        db_table = 'db_work_'
        verbose_name_plural = '流程实例表'

    def __str__(self):
        return self.pro_id
# 节点属性实例表


class NodeAttributeinstanceModel(models.Model):
    node_id = models.ForeignKey(NodeModel,on_delete=models.CASCADE,verbose_name='节点id')
    attr_id = models.ForeignKey(AttributeModel,on_delete=models.CASCADE,verbose_name='属性id')
    content = models.CharField('内容值',max_length=100)

    class Meta:
        db_table = 'db_NodeAttrInst'
        verbose_name_plural = '节点属性实例表'

    def __str__(self):
        return self.node_id

# 审批实例表


class ApproverTableModel(models.Model):
    yuan_id = models.ForeignKey(YuanGongModel,on_delete=models.CASCADE,verbose_name='员工id')
    wfi_id = models.ForeignKey(WorkflowInstanceModel,on_delete=models.CASCADE,verbose_name='流程实例id')
    date = models.DateTimeField(default=datetime.now(),verbose_name='申请时间')
    operato  = models.CharField(max_length=10,verbose_name='操作人')
    nodestate = models.IntegerField('申请, 0: 成功, 1: 驳回, 2: 等待中',default=2)

    class Meta:
        db_table = 'db_approver'
        verbose_name_plural = '审批实例表'

    def __str__(self):
        return self.yuan_id


